package com.app.mymusic.utils;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.NotificationCompat;
import android.widget.RemoteViews;

import com.app.mymusic.R;
import com.app.mymusic.ui.MainActivity;

/**
 * Created by Administrator on 2016/7/29.
 */
public class NotificationUtil {

    public NotificationUtil() {
    }

    private void showMusicStyleNotification(String title, String text, Context context)
    {
        int playPauseButtonPosition=0;
        NotificationManager manager= (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
        RemoteViews view=new RemoteViews(context.getPackageName(),R.layout.notification_play);
        view.setTextViewText(R.id.pc_name_tv,"gequ mingzi ");
        Notification notification1 = new NotificationCompat.Builder(context)
//                .setStyle(new NotificationCompat.MediaStyle()
//                        .setShowActionsInCompactView(
//                                new int[]{playPauseButtonPosition}))
                .setContent(view)
                .setSmallIcon(R.drawable.flag)
                .setTicker("ticker")
                .build();

        //定义Notification的各种属性
//        notification1.contentView = view;
        notification1.flags=Notification.FLAG_AUTO_CANCEL;
        notification1.defaults=Notification.DEFAULT_SOUND;
        // 通知的时间
        notification1.when = System.currentTimeMillis();
        PendingIntent pi= PendingIntent.getActivity(context,1,new Intent(context,MainActivity.class),PendingIntent.FLAG_CANCEL_CURRENT);
        notification1.contentIntent=pi;
        manager.notify(0,notification1);
    }
    private void showMediaStyleNotification(String title,String text,Context context)
    {
        Intent previeousIntent=new Intent("Previous");
        PendingIntent previousPendingIntent=PendingIntent.getBroadcast(context,1000,previeousIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        Intent pauseIntent=new Intent("Pause");
        PendingIntent pausePendingIntent=PendingIntent.getBroadcast(context,1001,pauseIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        Intent nextIntent=new Intent("Next");
        PendingIntent nextPendingIntent=PendingIntent.getBroadcast(context,1002,nextIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder notificationBuilder=createNormalNotificationBuilder(title,text,context);
        notificationBuilder.addAction(R.mipmap.ic_launcher,"Previous",previousPendingIntent).addAction(R.mipmap.ic_launcher,"Pause",pausePendingIntent).addAction(R.mipmap.ic_launcher,"Next",nextPendingIntent)
                .setStyle(new NotificationCompat.MediaStyle().setShowActionsInCompactView(new int[]{0,1,2}))
                .setVisibility(NotificationCompat.VISIBILITY_PRIVATE );
        NotificationManagerCompat notificationManager=NotificationManagerCompat.from(context);
        notificationManager.notify(7,notificationBuilder.build());
    }

    private NotificationCompat.Builder createNormalNotificationBuilder(String title,String text,Context context)
    {
        NotificationCompat.Builder notificationBuilder=new NotificationCompat.Builder(context);
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(title)
                .setContentText(text)
                .setAutoCancel(true)
                .setDefaults(NotificationCompat.DEFAULT_ALL);
        return notificationBuilder;
    }

    public  void test2()
    {
//       显示在锁屏界面 api 21
      /*  Intent previeousIntent=new Intent("Previous");
        PendingIntent pi=PendingIntent.getBroadcast(this,1000,previeousIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        MediaSession session = new MediaSession(this,"hello");
        Notification noti = new Notification.Builder(this)
                .setVisibility(Notification.VISIBILITY_PUBLIC)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle("Track title")
                .setContentText("Artist - Album")
                .addAction(R.mipmap.ic_launcher,"Previous", pi)
        .addAction(R.mipmap.ic_launcher,"Pause", pi)
         .addAction(R.mipmap.ic_launcher,"Next", pi)
         .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
         .setStyle(new Notification.MediaStyle()
                 .setMediaSession(session.getSessionToken())
         .setShowActionsInCompactView(0)).build();
         NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
         manager.notify(101, noti);*/
    }
}
